package com.the.ui.page.fragment.textview

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.view.View
import com.the.ui.R
import com.the.ui.databinding.FragmentColorTrackTextViewBinding
import com.the.ui.viewmodel.state.ColorTrackViewModel
import com.the.ui.widge.ColorTrackTextView
import com.theone.mvvm.base.viewmodel.BaseViewModel
import com.theone.mvvm.core.base.fragment.BaseCoreFragment
import com.theone.mvvm.ext.qmui.setTitleWitchBackBtn

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 * @author The one
 * @date 2021-11-05 13:48
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
class ColorTrackTextViewFragment:BaseCoreFragment<ColorTrackViewModel,FragmentColorTrackTextViewBinding>(),ValueAnimator.AnimatorUpdateListener {

    private val animator:ValueAnimator by lazy {
        ObjectAnimator.ofFloat(0f,1f).apply {
            duration = 3000
            addUpdateListener(this@ColorTrackTextViewFragment)
        }
    }

    override fun initView(root: View) {
        setTitleWitchBackBtn(R.string.color_track_text_view)
    }

    override fun createObserver() {

    }

    override fun onAnimationUpdate(animation: ValueAnimator?) {
        animation?.let {
//            mViewModel.progress.set(it.animatedValue as Float)
            mBinding.trackTextView.mCurrentProgress = it.animatedValue as Float
        }
    }

    private fun setAnimation(direction:ColorTrackTextView.Direction){
//        mViewModel.direction.set(direction)
        mBinding.trackTextView.mDirection = direction
        animator.start()
    }

    override fun getBindingClick(): Any = ProxyClick()

    inner class ProxyClick{

        fun leftToRight(){
            setAnimation(ColorTrackTextView.Direction.LEFT_TO_RIGHT)
        }

        fun rightToLeft(){
            setAnimation(ColorTrackTextView.Direction.RIGHT_TO_LEFT)
        }
    }


}